<include file="public@header"/>
</head>
<body>
<div class="wrap js-check-wrap">
    <ul class="nav nav-tabs">
        <li class="active"><a href="#">{$class_info['name']} 学生名单</a></li>
        <!-- <li><a href="{:url('Student/add_student')}">添加学生</a></li> -->
    </ul>
	<form class="js-ajax-form" action="#" method="post">
        <div class="table-actions">
			<input class="btn btn-primary" type="button" value="返回" onclick="javascript:history.back(-1)"></input>
            <input id="edit_student" class="btn btn-primary" type="button" value="修改资料"></input>
            <input id="hold_student" class="btn btn-primary" type="button" value="保持选择"></input>
            <a id="hold_student" class="btn btn-primary" type="button" href="{:url('admin/class/exp_class_students',array('class_id'=>$class_info['id']))}">导出名单</a>
            <input id="enroll" class="btn btn-primary" type="button" value="报名" onclick="doSelectCategory();" ></input>
			<button id="cancel_sign_in" class="btn btn-danger js-ajax-submit" type="submit" data-action="{:url('admin/class/cancel_sign_in')}" data-msg="您确定要操作这些学生退班吗？">退班</button>
			<input name="class_id" hidden="hidden" value="{$class_info['id']}"/>
        </div>
		<div class="table-cont" id='table-cont'>
        <table class="table table-hover table-bordered table-list" style="height:80%">
            <thead class="fixed-thead" id="head">
            <tr>
                <th>
                    <label>
                        <input type="checkbox" class="js-check-all" data-direction="x" data-checklist="js-check-x">
                    </label>
                </th>
                <th>ID</th>
                <th>姓名</th>
                <th>性别</th>
                <th>年级</th>
                <th>联系方式</th>
                <th>备用联系方式</th>
                <th>备注</th>
                <th>洋葱码</th>
            </tr>
            </thead>
            <foreach name="students_info" item="vo" key="i">
                <tr name='{$vo.student_id}'>
                    <th scope="row">
                        <input type="checkbox" class="js-check" data-yid="js-check-y" data-xid="js-check-x" name="ids[]"
                               value="{$vo.student_id}" title="ID:{$vo.student_id}">
                    </th>
                    <td><b>{$vo.student_id}</b></td>
                    <td>
                        {$vo.name}
					</td>
                    <td>{$vo.sex==1 ? '男' : ($vo.sex==2 ? '女' : '未知')}
                    </td>
                    <td>
						<php>
							$switch_date = date('m')>8 ? 1+date('Y')-$students_info[$i]['deg'] : date('Y')-$students_info[$i]['deg'];
						</php>
						<switch name="$switch_date">
							<case value="1">一年级</case>
							<case value="2">二年级</case>
							<case value="3">三年级</case>
							<case value="4">四年级</case>
							<case value="5">五年级</case>
							<case value="6">六年级</case>
							<case value="7">初一</case>
							<case value="8">初二</case>
							<case value="9">初三</case>
							<case value="10">高一</case>
							<case value="11">高二</case>
							<case value="12">高三</case>
							<default />未知
						</switch>
					</td>
                    <td>{$vo.phone}</td>
                    <td>{$vo.phone2|default='无'}</td>
                    <td>{$vo.note|default='未知'}</td>
					<td>{$vo.onion|default='未知'}</td>
                </tr>
            </foreach>
			</tbody>
        </table>
		</div>
        <ul class="pagination">{$page|default=''}</ul>
		
		<div name="sign_in" hidden="hidden">
			<input style="width:74%;float:left;" class="form-control" type="text" value="" placeholder="请选择班级" onclick="doSelectCategory();" id="js-categories-name-input" readonly="true"/>
			<input class="form-control" type="hidden" value="" name="class_id_post" id="js-categories-id-input"/>
			<!-- <input style="width:12%;float:left;margin-left:1%" class="btn btn-primary form-control" value="确认报名！" type="button" /> -->
			<button style="width:12%;float:left;margin-left:1%" class="btn btn-primary js-ajax-submit" type="submit" data-action="{:url('admin/class/sign_in_post')}">报名</button>
			<input style="width:12%;float:right;" class="btn btn-danger form-control" value="取消！" type="button" onclick="sign_in_hide();" />
		</div>
	</form>
</div>
<script src="__STATIC__/js/admin.js"></script>
<script src="__STATIC__/js/bootstrap-typeahead.js"></script>
<script src="__STATIC__/js/jquery.cookie.js"></script>
<script>
	function sign_in_hide(){
		$("div[name='sign_in']").hide();
	}

	function doSelectCategory() {
		$("div[name='sign_in']").show();
        var selectedCategoriesId = $('#js-categories-id-input').val();
        openIframeLayer("{:url('Class/select',array('id'=>'1'))}", '请选择班级', {
            area: ['900px', '500px'],
            btn: ['确定', '取消'],
            yes: function (index, layero) {
                //do something

                var iframeWin          = window[layero.find('iframe')[0]['name']];
                var selectedCategories = iframeWin.confirm();
                if (selectedCategories.selectedCategoriesId.length == 0) {
                    layer.msg('请选择分类');
                    return;
                }
                $('#js-categories-id-input').val(selectedCategories.selectedCategoriesId.join(','));
                $('#js-categories-name-input').val(selectedCategories.selectedCategoriesName.join(' '));
                //console.log(layer.getFrameIndex(index));
                layer.close(index); //如果设定了yes回调，需进行手工关闭
            }
        });
    }
	
	$(function(){
		$("#enroll").click(function(){
			$("#js-categories-name-input").focus();
		});
	});

	$(function(){
		$("#edit_student").click(function(){
			var ids = [];
			$("input[name='ids[]']").each(function () {
				if ($(this).is(':checked')) {
					ids.push($(this).val());
				}
			});
			if (ids.length == 1){
				var url = "{:url('Student/edit_student','',false,true)}" + "/id/" + ids;
				<!-- alert(url); -->
				window.location.href = url;
			}
			else{
				alert('请选择一个学生进行编辑');
			}
		});
	});
	
	$(function(){
		$("#hold_student").click(function(){
			var ids = [];
			$("input[name='ids[]']").each(function () {
				if ($(this).is(':checked')) {
					ids.push($(this).val());
				}
			});
			if (ids.length < 61){
				$.cookie('hold_student',ids,{path:'/'});
				<!-- alert($.cookie('hold_student')); -->
				alert('已保持选中！');
			}
			else{
				alert('一次最多操作60名学生');
			}
		});
	});

	$(function(){
		$("#add_student").click(function(){
			var url = "{:url('Student/add_student','',false,true)}";
			if($("#name").val()){
				url = url + "/name/" + $("#name").val();
			}
			if($("#phone").val()){
				url = url + "/phone/" + $("#phone").val();
			}
			window.location.href = url;
		});
	});

	$(function(){
		$("tr[name]").click(function(){
			var id = $(this).attr("name");
			var is_check = $("input[value='"+id+"']").prop("checked");
			if(is_check){
				$("input[value='"+id+"']").prop("checked",false);
				$(this).prop("class",false);
			}
			else{
				$("input[value='"+id+"']").prop("checked",true);
				$(this).prop("class","success");
			}
		});
	});

</script>
</body>
</html>